using MediatR;
using SumerCoreDevOps.Application.GitTriggers.Commands;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.GitTrigger;

namespace SumerCoreDevOps.Application.GitTriggers.Handlers;

/// <summary>
/// 创建 Git 触发规则命令处理器
/// </summary>
public class CreateGitTriggerRuleCommandHandler : IRequestHandler<CreateGitTriggerRuleCommand, GitTriggerRule>
{
    private readonly GitTriggerRuleManager _ruleManager;

    public CreateGitTriggerRuleCommandHandler(GitTriggerRuleManager ruleManager)
    {
        _ruleManager = ruleManager;
    }

    public async Task<GitTriggerRule> Handle(CreateGitTriggerRuleCommand request, CancellationToken cancellationToken)
    {
        return await _ruleManager.CreateRuleAsync(
            request.WorkflowId,
            request.Name,
            request.TriggerType,
            request.BranchPattern,
            request.TagPattern,
            request.PathFilter,
            request.CreatedBy);
    }
}
